#define ACTIVATE_NONE 0
#define ACTIVATE_WAIT 1
#define ACTIVATE_SPELL 2
#define ACTIVATE_ABILITY 3
#define ACTIVATE_DISCIPLINE 4
#define ACTIVATE_AA 5

objectdef Activating inherits BotBase
{
	variable string aSpell
	variable string aAbility
	variable string aDiscipline
	variable string aAA
	variable bool DoneActivating = TRUE
	variable int ActivateStart = ${LavishScript.RunningTime}
	variable int LastAction = ${LavishScript.RunningTime}
	variable int WaitUntil = ${LavishScript.RunningTime}
	
	method Spell(string Name)
	{
		This:EA["${Name}"]
		This.ActivateStart:Set[${LavishScript.RunningTime}]
		This.aSpell:Set[${Name}]
		This.DoneActivating:Set[FALSE]
	}
	 
	method Ability(string Name)
	{
		This.ActivateStart:Set[${LavishScript.RunningTime}]
		This.aAbility:Set[${Name}]
		This.DoneActivating:Set[FALSE]
	}
	
	method Discipline(string Name)
	{
		This.ActivateStart:Set[${LavishScript.RunningTime}]
		This.aDiscipline:Set[${Name}]
		This.DoneActivating:Set[FALSE]
	}

	method AA(string Name)
	{
		This.ActivateStart:Set[${LavishScript.RunningTime}]
		This.aAA:Set[${Name}]
		This.DoneActivating:Set[FALSE]
	}
	
	method Reset()
	{
		This.aSpell:Set[0]
		This.aAbility:Set[0]
		This.aDiscipline:Set[0]
		This.aAA:Set[0]
		This.DoneActivating:Set[TRUE]
	}

	member Valid()
	{
		if ${Me.Ability[${This.ActivateObject}](exists)} || ${Me.CombatAbility[${This.ActivateObject}](exists)} || ${Me.AltAbility[${This.ActivateObject}](exists)} || ${Me.SpellReady[${This.ActivateObject}]}
		{
			return TRUE
		}
		return FALSE
	}
	
	member Done()
	{
		if !${This.DoneActivating}
		{
			return FALSE
		}
		return TRUE
	}

	member State()
	{
		if ${LavishScript.RunningTime} < ${This.WaitUntil}
		{
			return ACTIVATE_WAIT
		}
		
		if ${Math.Calc[${LavishScript.RunningTime} - ${This.LastAction}]} < 1000
		{
			return ACTIVATE_WAIT
		}

		if ${This.aSpell.Length} > 0
		{
			return ACTIVATE_SPELL
		}
		
		if ${This.aAbility}
		{
			return ACTIVATE_ABILITY
		}

		if ${This.aDiscipline}
		{
			return ACTIVATE_DISCIPLINE
		}

		if ${This.aAA}
		{
			return ACTIVATE_AA
		}
				
		return ACTIVATE_NONE
	}
	
	method Pulse()
	{
		This.CurrentState:Set[${This.State}]
		;This:EA[${This.CurrentState}]
		switch ${This.CurrentState}
		{
			case ACTIVATE_SPELL
				CastSpell "${This.aSpell}"
				This.aSpell:Set[]
				This.LastAction:Set[${LavishScript.RunningTime}]
				This.WaitUntil:Set[${Math.Calc[${LavishScript.RunningTime} + ${Math.Calc[${Spell[${This.aSpell}].MyCastTime} * 1000]}]}]
				break
			case ACTIVATE_ABILITY
				DoAbility "${This.aAbility}"
				This.LastAction:Set[${LavishScript.RunningTime}]
				break
			case ACTIVATE_DISCIPLINE
				EQExecute ${This.aDiscipline}
				This.LastAction:Set[${LavishScript.RunningTime}]
				break
			case ACTIVATE_AA
				This.LastAction:Set[${LavishScript.RunningTime}]
				break
			case ACTIVATE_WAIT
				break
			case ACTIVATE_NONE
				This:Reset
				break
		}
	}
	 
	method Inject()
	{
		This:Reset
		Event[CORE_EVENT_PULSE]:AttachAtom[${This.ObjectName}:Pulse]
	}
	 
	method Shutdown()
	{
	}
}

